<template>
    <div class="fen1">
        <van-sidebar v-model="activeKey">
            <van-sidebar-item v-for="item in categoryList" :key="item.id" :title="item.name" @click="fenlFn(item.id)" />
        </van-sidebar>
        <!-- 照片部分 -->
        <ul>
            <div>
                <img :src="banner_url" height="140px" width="95%" />
                <h5>{{ front_desc }}</h5>
            </div>
            <!-- <div class="mytitle">111</div> -->
            <!-- 居家分类 -->
            <div class="mytitle">
                <span></span>
                <h3>----{{ name }}----</h3>
            </div>
            <!-- 列表 -->
            <van-grid :column-num="3">
                <van-grid-item v-for="item in subCategoryList" :key="item.id" :icon="item.wap_banner_url" :text="item.name" />
            </van-grid>
        </ul>
    </div>
</template>

<script>
import { getCategoryList, GetFenleiDataApi } from '@/utils/https.js';

export default {
    data() {
        return {
            categoryList: [], //数据存储
            // ------------
            activeKey: 0, //插件属性
            subCategoryList: [],
            banner_url: [],
            front_desc: [],
            name: [],
            wap_banner_url: [],
            namen: [],
        };
    },
    methods: {
        fenlFn(id) {
            getCategoryList().then(res => {
                this.front_desc = this.categoryList[this.activeKey].front_desc;
                this.banner_url = this.categoryList[this.activeKey].banner_url;
                this.name = this.categoryList[this.activeKey].name;
            });
            GetFenleiDataApi({ id }).then(res => {
                this.subCategoryList = res.data.data.currentCategory.subCategoryList;
            });
        },
    },
    created() {
        getCategoryList().then(res => {
            this.categoryList = res.data.data.categoryList;
            this.banner_url = this.categoryList[this.activeKey].banner_url;
            this.front_desc = this.categoryList[this.activeKey].front_desc;
            this.name = this.categoryList[this.activeKey].name;
            this.subCategoryList = res.data.data.currentCategory.subCategoryList;
        });
    },
};
</script>

<style lang="less" scoped>
.fen1 {
    width: 100%;
    background: #fff;
    display: flex;
    van-sidebar {
        width: 20%;
        background: #f7f8fa;
    }
    ul {
        width: 80%;
        div {
            width: 100%;
            position: relative;
            img {
                margin: 0 7px;
                border-radius: 5px;
                box-shadow: 0 0 6px #000;
                filter: brightness(0.5);
            }
            h5 {
                width: 120px;
                height: 50px;
                position: absolute;
                top: 48%;
                left: 25%;
                font-size: 16px;
                z-index: 111;
                color: #fff;
                display: block;
                margin: 0;
                text-align: center;
            }
        }
        .mytitle {
            width: 100%;
            height: 50px;
            position: relative;
            background: #fff;
            font-size: 16px;
        }
        span {
            width: 50%;
            height: 2px;
            background-color: #ccc;
            position: absolute;
            margin: auto;
            left: 0;
            top: 0;
            bottom: 0;
            right: 0;
        }
        h3 {
            width: 305;
            height: 40px;
            background: #fff;
            position: absolute;
            margin: auto;
            left: 0;
            top: 0;
            bottom: 0;
            right: 0;
            line-height: 40px;
            text-align: center;
            color: #000;
        }
    }
}
</style>
